﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>方向条件-按照部门计算</title>
    <link href="../../Comm/Style/Table0.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="../../Scripts/bootstrap/js/jquery.min.js"></script>
    <script type="text/javascript" src="../../Scripts/bootstrap/js/bootstrap.min.js"></script>
    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../Scripts/config.js" type="text/javascript"></script>
    <script src="../../Comm/Gener.js" type="text/javascript"></script>
    <script src="../../Scripts/easyUI/jquery-1.8.0.min.js" type="text/javascript"></script>
    <base target="_self" />
    <script type="text/javascript">

        //初始化页面函数.....
        $(function () {

            var condType = GetQueryString("CondType");
            var fk_flow = GetQueryString("FK_Flow");
            var fk_mainNode = GetQueryString("FK_MainNode");
            var fk_Node = GetQueryString("FK_Node");
            var toNodeID = GetQueryString("ToNodeID");
            var param = location.href.split("?")[1];

            var depts = new Entities("BP.Port.Depts");
            depts.RetrieveAll();

            var mypk = fk_Node + "_" + toNodeID + "_Dir_Depts";
            var cond = new Entity("BP.WF.Template.Cond");
            cond.MyPK = mypk;
            cond.RetrieveFromDBSources();

            $("#t1").append("<td colspan=3 class='GroupTitle' >部门选择</td>");
            for (var i = 0, len = depts.length; i < len; i++) {
                var td = "<td><input type='checkbox' id='dept_CB_" + depts[i].No + "' name='dept_CB_" + depts[i].No + "'/><label for='dept_CB_" + depts[i].No + "'>" + depts[i].Name + "</label></td>";
                if (i % 3 == 0) {
                    $("#t1").append("<tr></tr>");
                }
                $("#t1 tr:last").append(td);
            }

            var initDepts = cond.OperatorValue.split("@");
            for (i = 0, len = initDepts.length; i < len; i++) {
                if (initDepts[i] == "") continue;
                document.getElementById("dept_CB_" + initDepts[i]).checked = true;
            }
            //TODO 条件参数
            var atpara = cond.AtPara;
            if (atpara != "") {
                var initDDL_SpecOperWay = atpara.split("@")[1].split("=")[1];
                document.getElementById("initDDL_SpecOperWay").value = initDDL_SpecOperWay;
                document.getElementById("DDL_SpecOperWay").value = initDDL_SpecOperWay;

                var initTB_SpecOperPara = atpara.split("@")[2].split("=")[1];
                document.getElementById("TB_SpecOperPara").value = initTB_SpecOperPara;
                if (initDDL_SpecOperWay != 0) {
                    document.getElementById("TB_SpecOperPara").disabled = "";
                }
                document.getElementById("initTB_SpecOperPara").value = initTB_SpecOperPara;
                $("#span" + initDDL_SpecOperWay).css("display", "inline-block");
                $("#span" + initDDL_SpecOperWay).siblings().css("display", "none");
            }
            //条件参数 end
            //end
        });

        //执行保存..CondByDept_Save
        function Btn_Save_Click() {

            var param = location.href.split("?")[1];
            //获取所有选中的checkbox
            var depts = ",";
            $("input[type='checkbox']").each(function () {

                if (this.checked && this.name.indexOf("dept_CB_") == 0) {
                    depts += this.name.replace("dept_CB_", "") + ",";
                }
            });

            var frmData = $("#cc").serialize();
            //alert(frmData);
            $.ajax({
                data: frmData,
                type: 'post',
                async: true,
                url: Handler + "?DoType=CondByDept_Save" + "&FK_Node=" + GetQueryString("FK_Node") + "&m=" + Math.random() + "&depts=" + depts + "&" + param,
                dataType: 'html',
                success: function (data) {
                    if (data.indexOf('err@') >= 0) {
                        alert(data);
                        return;
                    }
                    alert(data);
                    window.location.href = window.location.href;
                    return;
                }
            });
        }

        //执行删除..
        function Btn_Delete_Click() {

            if (window.confirm('您确定要删除吗？') == false)
                return;

            var param = location.href.split("?")[1];
            $.ajax({
                data: '',
                type: 'post',
                async: true,
                url: Handler + "?DoType=CondByDept_Delete&FK_Node=" + GetQueryString("FK_Node") + "&m=" + Math.random() + "&" + param,
                dataType: 'html',
                success: function (data) {

                    if (data.indexOf('err@') >= 0) {
                        alert(data);
                        return;
                    }

                    window.location.href = window.location.href;
                    return;
                }
            });
        }

        function selChange() {
            //01.如果 文本框 有初始值就赋初值
            var idx = document.getElementById("DDL_SpecOperWay").value;
            var idxinit = document.getElementById("initDDL_SpecOperWay").value;
            if (idx == idxinit) {
                document.getElementById("TB_SpecOperPara").value = document.getElementById("initTB_SpecOperPara").value;
            }
            else {
                document.getElementById("TB_SpecOperPara").value = "";
            }

            //02.处理文本框样式
            if (idx == 0) {
                document.getElementById("TB_SpecOperPara").disabled = "disabled";
            } else {
                document.getElementById("TB_SpecOperPara").disabled = "";
            }
            //03.处理标签
            $("#span" + idx).css("display", "inline-block");
            $("#span" + idx).siblings().css("display", "none");
        }
    </script>

    <style type="text/css">
        ul .cond li
        {
            display: none;
            line-height: 50px;
        }
        
        ul .cond li .active
        {
            display: block;
        }
        
        select
        {
            display: inline-block;
            width: 200px;
        }
        
        .btn
        {
            display:inline-block;
            height:20px;
            background-color:#0099ff;
            text-decoration:none;
            color:#fff;
            padding:3px 15px;
            margin:10px 10px;
        }
        .lbls span
        {
            width:80px;
         }
    </style>
</head>
<body >
    <form id="cc">
    <div style="overflow:auto">
        <div style="width: 100%;max-height: 600px;overflow:auto">
            <table id="t1" class="Table" cellspacing="1" cellpadding="1" border="1" style="width: 100%;">
            </table>
        </div>
        <br />
        
        <div>
            指定的操作员：<select id="DDL_SpecOperWay" name="DDL_SpecOperWay" onchange="selChange()">
                <option selected="selected" value="0">当前操作员</option>
                <option value="1">指定节点的操作员</option>
                <option value="2">指定表单字段作为操作员</option>
                <option value="3">指定操作员编号</option>
            </select>
            <input type="hidden" name="initDDL_SpecOperWay" id="initDDL_SpecOperWay" value=" " />
            <input type="hidden" name="initTB_SpecOperPara" id="initTB_SpecOperPara" value=" " />
            <br />
            <br />            
            <span class="lbls">
                <span id="span0">参数：</span>
                <span id="span1" style="display: none">节点编号：</span>
                <span id="span2" style="display: none">表单字段：</span>
                <span id="span3" style="display: none">操作员编号：</span>
            </span>
            <input id="TB_SpecOperPara" name="TB_SpecOperPara" type="text" disabled="disabled" style="width: 200px;" />&nbsp;&nbsp;多个值请用英文“逗号”来分隔。
            <br />
            <a class="btn" href="javascript:Btn_Save_Click();">保&nbsp;存</a>&nbsp;&nbsp; 
            <a class="btn" href="javascript:Btn_Delete_Click();">删&nbsp;除</a>
            
        </div>
    </div>
    </form>
</body>
</html>
